package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Service;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据条件查询购物车集合
     * @param shoppingCart
     * @return
     */
    ShoppingCart query(ShoppingCart shoppingCart);


    /**
     * 更新商品数量
     *
     * @param
     */
    @Update("UPDATE shopping_cart set number=#{number} where id=#{id}")
    void updateNumberById(ShoppingCart cart);

    /**
     * 插入购物车数据
     *
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, user_id, dish_id, setmeal_id, dish_flavor, number, amount, image, create_time) " +
            " values (#{name},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{number},#{amount},#{image},#{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 根据用户id查看购物车
     * @param currentId
     * @return
     */
    @Select("SELECT * FROM shopping_cart where user_id=#{currentId}")
    List<ShoppingCart> getByUserId(Long currentId);

    /**
     * 删除购物车中的货品
     * @param id
     */
    @Delete("delete from shopping_cart where id= #{id}")
    void deleteById(Long id);

    /**
     * 清空购物车
     * @param shoppingCart
     */
    @Delete("delete from shopping_cart where user_id= #{userId}")
    void clean(ShoppingCart shoppingCart);
}
